package com.demo.inner;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
import me.chanjar.weixin.cp.bean.article.NewArticle;


/**
 * 企业内部开发：发送消息
 */
public class InnerMessageDemo extends InnerBaseService{
    private static final String user1 = "ChenXingXing";


    public static void main(String[] args) throws Exception {
        WxCpMessage cpMessage = null;
        int chooseIndex = 1;
        switch (chooseIndex){
            case 0:{
                cpMessage = TEXT();
                break;
            }
            case 1:{
                cpMessage = IMAGE();
                break;
            }
            case 3:{
                cpMessage = VOICE();
                break;
            }
            case 4:{
                cpMessage = VIDEO();
                break;
            }
            case 5:{
                cpMessage = NEWS();
                break;
            }
            default:{
                break;
            }
        }
        WxCpMessageSendResult result = wxCpService.messageSend(cpMessage);
        System.out.println(result);
    }


    /**
     * 文本消息
     * @return
     */
    public static WxCpMessage TEXT(){
        WxCpMessage message = WxCpMessage.TEXT()
            .toUser(user1)    // 用户Id
            .content("文本消息") // 消息
            .agentId(agentId)          // 应用Id
            .build();
        return message;
    }

    /**
     * 图片消息
     * @return
     */
    public static WxCpMessage IMAGE(){
        WxCpMessage message = WxCpMessage.IMAGE()
            .toUser(user1)
            .mediaId("1JwpbLSisNzaUb8dGiR6stmseQcRORha2Md9DeV829-1W_G56F6gjsO5ClJ7isccW")
            .agentId(agentId)
            .build();
        return message;
    }

    /**
     * 语音消息
     * @return
     */
    public static WxCpMessage VOICE(){
        WxCpMessage message = WxCpMessage.VOICE()
            .toUser(user1)
            .agentId(agentId)
            .mediaId("media_id")
            .build();
        return message;
    }


    /**
     * 视频消息
     * @return
     */
    public static WxCpMessage VIDEO(){
        WxCpMessage message = WxCpMessage.VIDEO()
            .toUser(user1)
            .agentId(agentId)
            .mediaId("media_id")
            .build();
        return message;
    }

    /**
     * 图文消息
     * @return
     */
    public static WxCpMessage NEWS(){
        NewArticle article1 = new NewArticle();
        article1.setUrl("URL");
        article1.setPicUrl("PIC_URL");
        article1.setDescription("Is Really A Happy Day");
        article1.setTitle("Happy Day");

        NewArticle article2 = new NewArticle();
        article2.setUrl("URL");
        article2.setPicUrl("PIC_URL");
        article2.setDescription("Is Really A Happy Day");
        article2.setTitle("Happy Day");

        WxCpMessage message = WxCpMessage.NEWS()
            .toUser(user1)
            .agentId(agentId)
            .addArticle(article1)
            .addArticle(article2)
            .build();
        return message;
    }

}
